
def myAtoi(self, s: str) -> int:
    s = s.strip()
    sign = '' # 负号
    nums = [] # 数字部分
    if len(s) != 0:
        if s[0] == '+':
            s = s[1:] # 舍弃正号不参与运算
        elif s[0] == '-':
            sign = s[0] # 暂存负号
            s = s[1:] # 舍弃负号不参与运算
    for char in s:
        if len(nums) == 0 and char == "0":
            continue
        if ord(char) < 48 or ord(char) > 57:
            break
        nums.append(char)
    s = ''.join(nums)
    if sign != '' and len(s) > 0:
        s = sign + s # 补上负号
    i32 = int(s) if len(s) > 0 else 0
    if i32 < -2147483648:
        i32 = -2147483648
    elif i32 > 2147483647:
        i32 = 2147483647
    return i32
